package B.w.OOday03;
/** 测试类 */
public class Test {
    public static void main(String[] args) {
     /* Dog dog=new Dog("小黑",2,"黑");
        System.out.println(dog.name);*/
        /*dog=null;//表示空，没有指向任何对象
        System.out.println(dog.name);//空指针异常*/

        //区别1：给引用类型数组的元素赋值时，需要new个对象
        //区别2：访问引用类型数组的元素属性/行为是，需要打点访问
        /*Dog[]dogs=new Dog[3];
        dogs[0]=new Dog("小黑",2,"黑");
        dogs[1]=new Dog("小白",1,"白");
        //dogs[2]=new Dog("小灰",1,"灰");
        //不赋值就是默认值，默认值为null，dogs[2]还是默认值，默认值表示为空（null：没有指向任何对象）
        System.out.println(dogs[0].name);//输出第一只狗狗的名字
        dogs[1].age=4;//修改第二只狗狗的年龄为6岁
        dogs[2].Swim();//第三只狗狗在游泳。。。上面null时此处找不到对象
        for(int i=0;i<dogs.length;i++){//遍历dogs数组
            System.out.println(dogs[i].name);//输出每只狗狗的名字
            dogs[i].eat();//每只狗狗吃饭
        }
        Fish[]fish=new Fish[3];
        fish[0]=new Fish("小黑",2,"黑");
        fish[1]=new Fish("小白",1,"白");
        fish[2]=new Fish("小灰",1,"灰");
        System.out.println(fish[0].name);
        fish[1].age=4;
        fish[2].Swim();
        for(int i=0;i<fish.length;i++){
            System.out.println(fish[i].name);
            fish[i].eat();
        }
        Chick[]chicks=new Chick[3];
        chicks[0]=new Chick("小黑",2,"黑");
        chicks[1]=new Chick("小白",1,"白");
        chicks[2]=new Chick("小灰",1,"灰");
        System.out.println(chicks[0].name);
        chicks[1].age=4;
        chicks[2].eat();
        for(int i=0;i<chicks.length;i++){
            System.out.println(chicks[i].name);
            chicks[i].eat();
        }*/
    }
}




















